package com.sky.controller.admin;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Controller
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    private DishService dishService;
    @ResponseBody
    @PostMapping("")
    public Result add(@RequestBody DishDTO dishDTO){
        return dishService.addDish(dishDTO);
    }
    @ResponseBody
    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO){
        log.info("分页查询：{}", dishPageQueryDTO);
        PageResult pageResult = dishService.pageQuery(dishPageQueryDTO);
        return Result.success(pageResult);
    }
    @ResponseBody
    @DeleteMapping("")
    @ApiOperation("删除菜品")
    public Result page(@RequestParam List<Integer> ids){
        log.info("分页查询：{}", ids);
        return dishService.delete(ids);
    }

    /**
     * 根据id查询查询菜品
     * @param
     * @return
     */
    @ResponseBody
    @GetMapping("/{id}")
    @ApiOperation("根据id查询菜品")
    public Result<DishVO> list(@PathVariable long id){
        return dishService.list(id);
    }
    @ResponseBody
    @PutMapping("")
    @ApiOperation("编辑菜品")
    public Result<DishVO> list(@RequestBody DishDTO dishDTO){
        return dishService.edit(dishDTO);
    }
}
